import request, { requestHttp } from "@/utils/request";
import { ResultData } from "@/api/types";

// 查询字典类型列表
export function listType(query: any) {
  return request({
    url: "/system/dict/type/page",
    method: "get",
    params: query
  });
}

// 查询字典类型详细
export function getType(dictId: number) {
  return request({
    url: "/system/dict/type/" + dictId,
    method: "get"
  });
}

// 新增字典类型
export function addType(data: any) {
  return request({
    url: "/system/dict/type",
    method: "post",
    data: data
  });
}

// 修改字典类型
export function updateType(data: any) {
  return request({
    url: "/system/dict/type",
    method: "put",
    data: data
  });
}

// 删除字典类型
export function delType(dictId: number) {
  return request({
    url: "/system/dict/type/" + dictId,
    method: "delete"
  });
}

// 刷新字典缓存
export function refreshCache() {
  return request({
    url: "/system/dict/type/refreshCache",
    method: "delete"
  });
}

// 导出字典类型
export function exportType(query: any) {
  return request({
    url: "/system/dict/type/export",
    method: "get",
    responseType: "blob",
    params: query
  });
}

export interface DictType {
  /**
   * 字典名称
   */
  dictName: string;

  /**
   * 字典类型
   */
  dictType: string;

  /**
   * 状态（0正常 1停用）
   */
  status: string;

  /**
   * 备注
   */
  remark: string;
}

// 获取字典选择框列表
export const optionselect = (): Promise<ResultData<DictType[]>> => requestHttp.get("/system/dict/type/optionselect");
